import { Button, Empty, Modal, Result, Steps } from 'antd';
import { useState, useEffect, useContext } from 'react';
import RiskReportContext from '../../RiskReportContext';
export default function Scbg(props) {
    const { result } = props;

    const { zhData, yxfxData, zhjcData } = useContext(RiskReportContext);
    // console.log(zhData, yxfxData, zhjcData)
    const [loading, setLoading] = useState();

    //后端接口
    const url = '/admin-api/ybyj/fxpg/genWord'

    //后端接口的参数 fxpg 

    //     const formData=new FormData();
    //     formData.append('image1',result?.['mapData1']?.img);
    //     formData.append('image1',result?.['mapData2']?.img);
    //     formData.append('image1',result?.['mapData3']?.img);
    //     formData.append('image1',result?.['mapData4']?.img);


    return <div className='fill layout-v center' style={{
        justifyContent: "center",
        marginTop: 20
    }}>

        <Result
            status="success"
            title="报告已准备完毕"
            extra={[
                <Button loading={loading} type="primary" key="download" size="large"
                    onClick={() => {
                        const params = {
                            "cztfbt": result.mapData1?.img,
                            "distance": yxfxData.radius * 1000,
                            // "glbm": "广元市应急管理局",
                            "jydwfbt": result.mapData2?.img,
                            "jydwsl": zhjcData.jydw?.count || 0,
                            "jydwDistance": zhjcData.jydw?.radius * 1000,
                            // "shcs": "成都市",
                            "wxcc": 0,
                            "wxhs": 0,
                            "wxrs": 0,
                            "wzcbkfbt": result.mapData4?.img,
                            "wzcbksl": zhjcData.wzcbd?.count || 0,
                            "wzcbkDistance": zhjcData.wzcbd?.radius * 1000,
                            "yfys": zhData.yfys,
                            "yjbncssl": zhjcData.bncs?.count || 0,
                            "yjbnsfbt": result.mapData3?.img,
                            "yjbnsfw": zhjcData.bncs?.radius * 1000,
                            // "shcsGeom": "POINT(23 65)",
                            "yxfwsl": 0,
                            "yxjj": 0,
                            "yxmjcssl": 0,
                            "yxntmj": 0,
                            "yxrk": 0,
                            // "zdmc": zhData,
                            "zhlx": zhData.yhlx,
                            "zhxxdz": zhData.xzqhmc,
                            "sourceGeom": zhData.geom
                        }
                        setLoading(true);
                        fetch(url, {
                            method: 'POST',
                            headers: {
                                'Content-Type': "application/json;charset=UTF-8",
                            },
                            body: JSON.stringify(params),
                            // redirect: 'follow'
                        }).then(resp => {
                            return resp.blob();
                        }).then(resp => {
                            const blob = new Blob([resp], { type: '.doc' });
                            const url = URL.createObjectURL(blob);
                            var link = document.createElement('a');
                            link.href = url;
                            link.download = '评估报告.doc';
                            link.click();


                            // if (response.ok) {
                            //     response.blob().then(blob => {
                            //         const file = document.createElement('a');
                            //         file.download = "w.word";
                            //         file.href = URL.createObjectURL(blob);
                            //         file.click();
                            //     });
                            // } else {
                            //     console.log('请求失败');
                            // }
                        }).finally(e => {
                            setLoading(false);
                        }).catch(error => console.log(error));
                    }} >
                    点击此处生成并下载报告
                </Button>
            ]}
        />
    </div>
}